package com.cskaoyan.service;

import com.cskaoyan.bean.zhao_order_bean.BasePageData;
import com.cskaoyan.bean.Log;
import com.cskaoyan.bean.LogExample;
import com.cskaoyan.bean.basebean.BaseParam;
import com.cskaoyan.mapper.LogMapper;
import com.cskaoyan.utils.MarketPageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    LogMapper logMapper;

    @Override
    public BasePageData quaryLogList(String name, BaseParam param) {
        MarketPageUtil.startPage(param);
        LogExample logExample = new LogExample();
        LogExample.Criteria criteria = logExample.createCriteria();
        if (!StringUtils.isEmpty(name)) {
            criteria.andAdminLike("%" + name + "%");
        }

        logExample.setOrderByClause(param.getSort() + " " + param.getOrder());
        List<Log> logs = logMapper.selectByExample(logExample);
        return BasePageData.ok(logs);
    }
     /*private static final String LOG_CONTENT="[类名]:%s,[方法]:%s,[参数]:%s,[IP]:%s";
    @Override
    public void put(JoinPoint joinPoint, String methodName, String module, String description) {
        Log log = new Log();
        Subject subject = SecurityUtils.getSubject();
        Admin admin = (Admin) subject.getPrincipals().getPrimaryPrincipal();
        log.setAdmin(admin.getUsername());
        //log.setIp(); //admin表
        //log.setType(); //1 订单操作 2.安全操作
        //log.action 登录 退出 删除 发货
        //log.status 成功 失败
        //log.result 发货--》订单编号 失败 ---》密码错误。。
    }*/

    @Override
    public void insertLogInfo(Log log) {
        logMapper.insertSelective(log);
    }

}
